home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / boostrs.arc / FINDSTR.ASM < prev    next >
Assembly Source File  |  1985-11-08  |  3KB  |  168 lines

  1. ;*****************************************************
  2. ;
  3. ;        Procedure FindStr (X : ColumnType;
  4. ;                           Y : RowType;
  5. ;                           S : AnyString;
  6. ;                           O : Integer;
  7. ;                       var E : Integer);
  8. ;
  9. ;               Places the cursor at offset O from S.
  10. ;               Search begins in video memory at X,Y.
  11. ;
  12. ;               E = 0, S found
  13. ;               E = 1, S not found
  14. ;
  15. ;               O = zero, cursor at S[1]
  16. ;               O < zero, cursor to left of S
  17. ;               O > zero, cursor to right of S
  18. ;
  19. ;*****************************************************
  20. FINDSTR proc    near
  21.     push    bp
  22.     mov    bp,sp
  23.     push    ds
  24.  
  25.     mov    bx,[bp+4]    ;  address of error flag
  26.     mov    [bx],0        ;  init to zero
  27. ;
  28. ;*** Determine Video address
  29. ;
  30.     mov    bx,449h
  31.     xor    ax,ax
  32.     mov    ds,ax
  33.     mov    al,[bx]
  34.     cmp    al,7
  35.     jne    graphx
  36.     mov    dx,0B000h
  37.     jmp    c001
  38. graphx:
  39.     mov    dx,03DAh    ; for IBM CGA,
  40. VR:    in    al,dx        ; we must do this
  41.     and    al,1000b    ; so we won't see
  42.     jz    vr        ; snow . . .
  43.     dec    dx
  44.     dec    dx
  45.     mov    al,21h
  46.     out    dx,al        ; disable video
  47.     mov    dx,0B800h
  48. C001:    mov    es,dx
  49. ;
  50. ;***  Compute X,Y offset
  51. ;
  52.     mov    di,[bp+266]    ;  Y
  53.         dec     di              ;  (Y-1)
  54.     mov    dx,di        ;  Save in DX
  55.     mov    cl,7
  56.     shl    dx,cl        ;  (Y-1) * 128
  57.     mov    cl,5
  58.     shl    di,cl        ;  (Y-1) *  32
  59.     add    di,dx        ;  (Y-1) * 160
  60.     mov    ax,[bp+268]    ;  X into AX
  61.     dec    ax        ;  (X-1)
  62.     shl    ax,1        ;  2 * (X-1)
  63.     add    di,ax        ;  byte offset
  64. ;
  65. ;***  Find string S on screen
  66. ;
  67.     mov    cx,4000
  68.     sub    cx,di
  69.     shl    cx,1        ; length of search
  70. ;
  71. INIT:    lea    bx,[bp+11]
  72.     mov    al,ss:[bx]    ; 1st char of S
  73.     mov    dl,[bp+10]    ; len of S
  74. SCAN:
  75.     cmp    al,es:[di]
  76.     je    got1
  77.     inc    di
  78.     inc    di
  79.     dec    cx
  80.     jcxz    enable        ; S not found
  81.     jmp    scan        ; keep looking
  82. ;
  83. GOT1:   sub     dl,1
  84.     jz    enable
  85. NEXT1:    inc    di
  86.     inc    di
  87.     inc    bx
  88.     mov    al,ss:[bx]
  89.     cmp    al,es:[di]
  90.     jne    Init
  91.     sub    dl,1
  92.     jz    enable
  93.     dec    cx
  94.     jcxz    enable
  95.     jmp    next1
  96. ;
  97. ;***  enable video signal
  98. ;
  99. ENABLE:
  100.     mov    dx,es
  101.     cmp    dx,0B800h
  102.     jne    skip
  103.     mov    dx,03D8h
  104.     mov    al,29h
  105.     out    dx,al        ; enable video
  106.     or    cx,cx
  107.     jz    not_found
  108. ;
  109. ;***  adjust DI according to offset value, O
  110. ;
  111. SKIP:    add    di,2
  112.         mov     ax,[bp+8]       ; O
  113.     sub    ax,0        ; O:0
  114.     jg    gt_zero
  115.     mov    dl,[bp+10]    ; len of S
  116.     shl    dl,1
  117.     xor    dh,dh
  118.     sub    di,dx        ; di -> S[1]
  119.     sub    ax,0        ; O=0?
  120.     jz    m_cursor
  121.     neg    ax        ; O < 0
  122.     shl    ax,1        ; compute offset
  123.     sub    di,ax        ; adjust di
  124.     jmp    m_cursor
  125. GT_ZERO:
  126.     dec    ax
  127.     shl    ax,1
  128.     add    di,ax        ; cursor address
  129.  
  130. ;
  131. ;***  Set Cursor
  132. ;
  133. M_CURSOR:
  134.     cmp    di,0
  135.     jge    max_chk
  136.     xor    di,di
  137.     jmp    end_chks
  138. max_chk:
  139.     cmp    di,3998
  140.     jbe    end_chks
  141.     mov    di,3998
  142. end_chks:
  143.         mov     ax,di
  144.     mov    bx,160
  145.     div    bl
  146.     shr    ah,1        ; remainder is col
  147.     mov    dl,ah
  148.     mov    dh,al        ; quotient is row
  149.     mov    ah,2        ; set cursor routine
  150.     int    10h        ; call BIOS
  151.     jmp    return
  152. ;
  153. ;*** Set error flag to 1
  154. ;
  155. NOT_FOUND:
  156.     mov    bx,[bp+4]
  157.     mov    ax,[bp+6]
  158.     mov    ds,ax
  159.     mov    [bx],1
  160. ;
  161. ;***  Return
  162. ;
  163. RETURN:
  164.     pop    ds
  165.     mov    sp,bp
  166.     pop    bp
  167.     ret    266
  168. FINDSTR endp